<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$setting.webname} - 修改专业课程</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/public/static/admin/layui/css/layui.css" rel="stylesheet">
    <link href="/public/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/public/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/public/static/admin/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="/public/static/admin/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
    <link href="/public/static/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <style>
        #demo2 img{
            height: 110px;
        }
    </style>

</head>

<body class="gray-bg">
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <h2>专业课程管理</h2>
        <ol class="breadcrumb">
            <li>
                <a href="{:url('Admins/admin')}">主页</a>
            </li>
            <li>
                <strong>修改专业课程</strong>
            </li>
        </ol>
    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加资讯</h5>
                </div>

                <div class="ibox-content">
                    <form class="form-horizontal">
                        <!--标题-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">标题：</label>
                            <div class="col-sm-6">
                                <input type="text" placeholder="请输入新闻标题" id="title" value="{$data.title}" class="form-control">
                            </div>
                            <div class='col-sm-4'></div>
                        </div>
                        <!--关键词-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">关键词：</label>
                            <div class="col-sm-6">
                                <input type="text" placeholder="请输入关键词（用逗号隔开）" value="{$data.key}"  id="key" class="form-control">
                            </div>
                            <div class='col-sm-4'></div>
                        </div>
                        <!--描述-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">描述：</label>
                            <div class="col-sm-6">
                                <input type="text" placeholder="请输入描述" id="desc"  value="{$data.desc}"  class="form-control">
                            </div>
                            <div class='col-sm-4'></div>
                        </div>
                        <!--浏览量-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">浏览量：</label>
                            <div class="col-sm-6">
                                <input type="number" placeholder="请输入浏览量" id="hits" class="form-control"  value="{$data.hits}" >
                            </div>
                            <div class='col-sm-4'></div>
                        </div>

                        <!--原来路径地址-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">原路径地址：</label>
                            <div class="col-sm-6">
                               {if condition='empty($data.cover)'}无{else /}<input type="text" placeholder="请输入网络图片地址" id="photo3" value="{$data.cover}" readonly class="form-control">{/if}
                            </div>
                            <div class='col-sm-4'>如果不修改一下图片选择留空即可。</div>
                        </div>
                        <!--图片地址-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">文章主图（网络图片）：</label>
                            <div class="col-sm-6">
                                <input type="text" placeholder="请输入网络图片地址" id="photo2" class="form-control">
                            </div>
                            <div class='col-sm-4'>如果是本地图片请使用【本地上传】如果两个都有图片以本地上传的为主，网络图片将不被保存。可以为空</div>
                        </div>
                        <!--图片上传-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">文章主图（本地上传）：</label>
                            <div class="col-sm-6">
                                <input type="button" class="btn btn-success" value="已上传的图片" id="selffile">
                                <button type="button" class="btn btn-info" id="test1">本地上传</button>
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="demo1" style='max-width:100%'>
                                    <p id="demoText"></p>
                                </div>
                            </div>
                            <div class='col-sm-4'>如果是网络图片路径请使用【网络图片】，如果两个都有图片以本地上传的为主，网络图片将不被保存。可以为空</div>
                        </div>
                        <!--资讯类型-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">资讯类型：</label>
                            <div class="col-sm-6">
                                <select class="form-control m-b" name="status" id="newstype">
                                    {foreach $list as $k=>$v}
                                    <option value="{$v.id}">{$v.type_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class='col-sm-4'></div>
                        </div>
                        <!--排序-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序类型：</label>
                            <div class="col-sm-6">
                                <select class="form-control m-b" name="status" id="sorttype">
                                    <option value="3">普通</option>
                                    <option value="2">最新</option>
                                    <option value="1">置顶</option>
                                </select>
                            </div>
                            <div class='col-sm-4'>同类型后添加的将会在最开始</div>
                        </div>
                        <!--状态-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">状态：</label>
                            <div class="col-sm-6">
                                <select class="form-control m-b" name="status" id="status">
                                    <option value="1">显示</option>
                                    <option value="2">不显示</option>
                                </select>
                            </div>
                            <div class='col-sm-4'></div>
                        </div>
                        <!--新闻内容-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">新闻内容：</label>
                            <div class="col-sm-6">
                                <div class="ibox-content no-padding" >
                                    <div class="summernote" id="content">
                                        {$data.content}
                                    </div>
                                </div>
                            </div>
                            <div class='col-sm-4'></div>
                        </div>
                        <!--确认-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label"></label>
                            <div class="col-sm-6">
                                <button type="button" class="btn btn-info btn-sm btn-block" id="save"> 保存修改</button>
                            </div>
                            <div class='col-sm-4'></div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<style>
    .layer_notive{
        width: 700px;
        margin: 20px auto;
        min-height: 500px;
        display: none;
    }
    .layer_notive ul li{
        float:left;
        margin:5px;
        width: 220px;

    }
    .layer_notive ul li img{
        max-width: 100%;
        padding:1px;
        border:2px solid #ccc;
        opacity: 0.7;
    }
    .active{
        border:2px solid green!important;
        opacity: 1!important;
    }
</style>
<!--弹出已上传的图片-->
<div class="layer_notive" >
    <ul id="imglist"></ul>
    <div style="clear:both"></div>
</div>
<!-- 全局js -->
<script src="/public/static/admin/layui/layui.js"></script>
<script src="/public/static/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="/public/static/admin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script src="/public/static/admin/js/content.js?v=1.0.0"></script>
<script src="/public/static/admin/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
<script>
    $("#newstype option[value='{$data.newstype}']").prop("selected",true);
    $("#sorttype option[value='{$data.sorttype}']").prop("selected",true);
    $("#status option[value='{$data.status}']").prop("selected",true);
    layui.use('upload', function() { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer,upload = layui.upload; //独立版的layer无需执行这一句
        var photo = "";

        $("#save").click(function () {
            //如果修改时选择了本地上传则图片以本地上传为主，如果不是本地上传而是填写了网络地址则保存网络地址，如果本地上传和网络地址都填写了则本地上传有限，如果都本地上传和网络地址都保留为空则保存原来的地址
            if(photo != "") {
                photo = photo;
            }else {
                if ($("#photo2").val() == "") {
                    photo = $("#photo3").val();
                } else {
                    photo = $("#photo2").val();
                }
            }
            $.post("{:url('Newss/toUpdate')}", {
                id:{$data.id},
                title: $("#title").val(),
                key: $("#key").val(),
                desc: $("#desc").val(),
                hits: $("#hits").val(),
                cover:photo,
                status: $("#status").val(),
                newstype:$("#newstype").val(),
                sorttype: $("#sorttype").val(),
                content: $('#content').code()
            }, function (data) {
                top.layer.msg(data.msg, {time: 2000,shade:0.5}, function () {
                    if (data.url) {
                        window.location.href = data.url;
                    }
                });
            });
        });

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: "{:url('Newss/upload')}"
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code == 0){
                    return top.layer.msg('上传失败',{shade:0.5});
                }else if(res.code){
                    //上传成功
                    photo = "/public/static/admin/uploads/news/"+res.photo;
                    return top.layer.msg('上传成功',{shade:0.5});
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
        //显示本地图片
        $("#selffile").click(function () {
            $.post("{:url('Base/getmyfiles')}",{path:"/public/static/admin/uploads/news"},function(data){
                console.log(data);
                var str = "";
                for( i in data.msg){
                    str += "<li><img src='/public/static/admin/uploads/news/"+data.msg[i]+"' class='imglist' onclick='changecss(this)' alt=''></li>";
                }
                $("#imglist").html(str);
                //页面层
                layer.open({
                    type: 1,
                    skin: false, //加上边框
                    title: "已上传的图片",
                    area: ['700px', '600px'], //宽高
                    btn:["确认","取消"],
                    content: $(".layer_notive"),  //调到新增页面
                    yes:function(){
                        var newImgsrc = $(".active").attr("src");
                        $('#demo1').attr('src', newImgsrc); //图片链接（base64）
                        $('#demo1').attr('width','100%');
                        photo = newImgsrc;
                        layer.closeAll();
                    }
                });
            });
        });

    });
    //点击图片选择图片
    function changecss(obj){
        $(".imglist").removeClass("active");
        $(obj).addClass("active");
    }
    $(".check").click(function(){
        if($(this).attr('class') == "fa fa-square-o check"){
            $(this).attr('class',"fa fa-check-square-o check");
        }else{
            $(this).attr('class',"fa fa-square-o check");
        }
    });
</script>
<!-- SUMMERNOTE -->
<script src="/public/static/admin/js/plugins/summernote/summernote.min.js"></script>
<script src="/public/static/admin/js/plugins/summernote/summernote-zh-CN.js"></script>
<script>
    $(document).ready(function () {

        $('.summernote').summernote({
            lang: 'zh-CN'
        });

    });
    // var edit = function () {
    //     $("#eg").addClass("no-padding");
    //     $('.click2edit').summernote({
    //         lang: 'zh-CN',
    //         focus: true
    //     });
    // };
    // var save = function () {
    //     $("#eg").removeClass("no-padding");
    //     var aHTML = $('.click2edit').code(); //save HTML If you need(aHTML: array).
    //     $('.click2edit').destroy();
    // };
</script>

</body>
</html>
